<template>
  <div class="archive">
    <div class="ar-title">
      <p>归</p>
      <p>档</p>
    </div>
    <div class="ar-left">
      <vue-scroll :ops="ops" ref="vst">
        <div
          class="timelinebox"
          v-loading="loading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
        >
          <el-timeline>
            <el-timeline-item
              v-for="(item, index) in articleData"
              :key="index"
              :timestamp="item.date"
              placement="top"
              type="primary "
            >
              <el-card>
                <p class="ititle">{{ item.title }}</p>
                <el-divider content-position="right">{{
                  item.category[0]
                }}</el-divider>
              </el-card>
            </el-timeline-item>
          </el-timeline>
        </div>
      </vue-scroll>
    </div>
    <div
      class="ar-right"
      v-loading="rightloading"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
    >
      <div class="rtitle">标签云</div>
      <div class="rcount">
        <span>文章：{{ count }}</span>
        <span>分类：{{ catecount }}</span>
      </div>
      <div class="catebox">
        <div
          class="cate-item"
          v-for="(item, index) in categoryData"
          :key="index"
          :class="getClass(index)"
        >
          <span>{{ item.name }}</span>
          <span>{{ "(" + item.count + ")" }}</span>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { GetArticle, GetCategory } from "../../api/index"
export default {
  name: "archive",
  data() {
    return {
      loading: true,
      rightloading: true,
      articleData: [],
      categoryData: [],
      count: 0,
      catecount: 0,
      typeClass: ["primary", "success", "info", "warning", "danger"],
      ops: {
        //vuescroll的配置
        vuescroll: {
          sizeStrategy: "percent",
          detectResize: true,
        },
        scrollPanel: {},
        rail: {},
        bar: {
          showDelay: 500,
          onlyShowBarOnScroll: false,
          keepShow: true,
          background: "#b3c0d1",
          opacity: 1,
          hoverStyle: false,
          specifyBorderRadius: false,
          minSize: false,
          size: "6px",
          disable: false,
        },
      },
    }
  },
  created() {
    this.getartile()
    this.getcategory()
  },
  computed: {
    getclass: function() {
      return function(index) {
        var newIndex = index % 5
        return this.typeClass[newIndex]
      }
    },
  },
  methods: {
    getartile(data) {
      GetArticle(data).then((res) => {
        this.articleData = []
        const { data, status, count } = res
        if (status) {
          this.articleData.push(...data)
          this.count = count
          this.loading = false
        }
      })
    },
    getcategory(data) {
      GetCategory(data).then((res) => {
        this.categoryData = []
        const { data, status } = res
        if (status) {
          this.categoryData.push(...data)
          this.catecount = this.categoryData.length
          this.rightloading = false
        }
      })
    },
    getClass(index) {
      var newIndex = index % 5
      return this.typeClass[newIndex]
    },
  },
}
</script>
<style lang="scss" scoped>
.archive {
  margin: 20px;
  height: calc(100% - 40px);
  width: 1000px;
  background: white;
  display: flex;
  position: relative;
  .ar-title {
    position: absolute;
    top: -10px;
    left: -30px;
    width: 60px;
    height: 80px;
    background: #409eff;
    color: white;
    text-align: center;
    border-radius: 5px;
    z-index: 2147483641;
    font-size: 20px;
    font-weight: bold;
    box-shadow: 0 10px 8px rgba(10, 16, 20, 0.24),
      0 0 8px rgba(10, 16, 20, 0.12);
    p {
      margin: 0px;
      height: 40px;
      line-height: 40px;
    }
  }
  .ar-left {
    box-sizing: border-box;
    padding: 10px;
    width: 550px;

    .timelinebox {
      padding: 20px 40px;
      min-height: 400px;
    }
  }
  .ar-right {
    width: 450px;
    background: rgb(224, 226, 230);
    position: relative;
    .rtitle {
      position: absolute;
      top: 10px;
      left: 10px;
      width: 130px;
      letter-spacing: 15px;
      text-indent: 15px;
      text-align: center;
      height: 50px;
      line-height: 50px;
      background: #409eff;
      color: white;
      text-align: center;
      border-radius: 5px;
      z-index: 999;
      font-size: 16px;
      font-weight: bold;
      box-shadow: 0 10px 8px rgba(10, 16, 20, 0.24),
        0 0 8px rgba(10, 16, 20, 0.12);
    }
    .rcount {
      height: 80px;
      line-height: 80px;
      text-align: right;
      padding: 0px 20px;
      span {
        color: rgb(81, 131, 165);
        margin-left: 10px;
      }
    }
    .catebox {
      margin: 0px 5px;
      .cate-item {
        display: inline-block;
        padding: 0px 10px;
        height: 30px;
        line-height: 30px;
        margin: 7px 5px;
        color: white;
        border-radius: 5px;
        box-shadow: 0 5px 8px rgba(10, 16, 20, 0.24),
          0 0 8px rgba(10, 16, 20, 0.12);
        span:nth-child(2) {
          margin-left: 5px;
        }
      }
    }
  }
  .el-card {
    width: 420px;
  }
  //    typeClass:["primary","success","info","warning","danger"],
  .primary {
    background: rgb(64, 158, 255);
  }
  .success {
    background: #67c23a;
  }
  .info {
    background: #124e69;
  }
  .warning {
    background: #e6a23c;
  }
  .danger {
    background: #f56c6c;
  }
}
</style>
